package dataStructure;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


public class ListNode<DataT> {
	DataT content;
	ListNode<DataT> previous;
	ListNode<DataT> next;
	
	public ListNode(DataT content) {
		this.content=content;
	}
	
	public DataT getContent(){
		return this.content;
	}
	
	public void setNext(ListNode<DataT> nxt){
		this.next=nxt;
	}
	
	public ListNode<DataT> getNext(){
		return this.next;
	}
	
	public void setPrevious(ListNode<DataT> prev){
		this.previous=prev;
	}
	
	public ListNode<DataT> getPrevious(){
		return this.previous;
	}
	
	public void printContent() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException{
		Class<?> c=this.getContent().getClass();
		Method pC=c.getDeclaredMethod("printContent");
		pC.invoke(this.getContent());
	}

	public Object getAttrVal(String field) throws SecurityException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		Class<?> c=this.getContent().getClass();
		Method pC;
		
		try {
			pC = c.getDeclaredMethod("getAttrVal", field.getClass());
			return pC.invoke(this.getContent(), field); 
		} catch (NoSuchMethodException e) {
			Field f;
			try {
				f = c.getDeclaredField(field);
		    	f.setAccessible(true);
				Object result= f.get(this.getContent());
				return result;
			} catch (NoSuchFieldException e1) {
			}
		}
		return null;
	}
}